//
//
//

#ifndef MYANDROID_LOG_HELPER_H
#define MYANDROID_LOG_HELPER_H

#include <jni.h>
#include <string>

#ifdef __android
#include <android/log.h>

#define  LOG_TAG    "JniHelper"

#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__);

#ifdef __DEBUG
#define  LOGD(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__);
#else
#define  LOGD(...)
#endif

#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__);

#else

#define  LOGI(...)  printf(__VA_ARGS__);
#define  LOGD(...)  printf(__VA_ARGS__);
#define  LOGE(...)  printf(__VA_ARGS__);

#endif

#include <sstream>
using namespace std;

template <int N=0>
inline ostream &_printStream(ostream &os)
{
    return os;
};

template <typename T0,typename... TN>
inline ostream &_printStream(ostream &os,T0 && t0, TN && ... tn){
    os<<t0;
    return _printStream(os,tn...);
};

#include <iostream>

class logger{
    stringstream ss;
public:

    template <typename... TN>
    inline stringstream & i(TN && ... tn){
        _printStream(ss,tn...);
        std::cout<<ss.str()<<std::endl; //LOGI("%s",ss.str().c_str());
        return ss;
    }


    template <typename... TN>
    inline stringstream & d(TN && ... tn){
        _printStream(ss,tn...);
        std::cout<<ss.str()<<std::endl; //LOGI("%s",ss.str().c_str());
        return ss;
    }

    template <typename... TN>
    inline stringstream & e(TN && ... tn){
        _printStream(ss,tn...);
        std::cout<<ss.str()<<std::endl; //LOGE("%s",ss.str().c_str());
        return ss;
    }

};


#define  LOGIS(...)  ::logger().i(__VA_ARGS__);

#ifdef __DEBUG
#   define  LOGES(...)  ::logger().e("[cpp:",__FILE__,", ",__LINE__,"] ", ## __VA_ARGS__);
#   define  LOGDS(...)  ::logger().d("[cpp:",__FILE__,", ",__LINE__,"] ", __VA_ARGS__);
#else
#   define  LOGES(...)  ::logger().e(__VA_ARGS__);
#   define  LOGDS(...)  ::logger().d(__VA_ARGS__);
#endif










#endif //MYANDROID_LOG_HELPER_H
